package com.xzy.seckill.service.mq;

import cn.hutool.json.JSONUtil;
import com.xzy.seckill.pojo.entity.Order;
import com.xzy.seckill.pojo.entity.SeckillOrder;
import com.xzy.seckill.pojo.vo.SeckillGoodDetailVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MQSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;


    /**
     * 发送减库存消息入队
     */
    public void sendStockTicket(String goodId){

       // log.info("扣减"+goodId+"号商品库存消息入队");
        rabbitTemplate.convertAndSend("secExchange","secKill.stock",goodId);
    }

    /**
     * 发送下单消息入队
     */
    public void sendOrder(Order order){

        String mes = JSONUtil.toJsonStr(order);
      //  log.info(order.getUserId()+"号用户"+order.getGoodsId() + "号商品入单消息入队");
        rabbitTemplate.convertAndSend("secExchange","secKill.order",mes);

    }

}
